#ifndef RBT_FILE_STREAM_INCLUDE
#define RBT_FILE_STREAM_INCLUDE

#include "StreamConvert.h"
#include <Windows.h>
RETURNCODE E_OPEN_FILE         = -201;
RETURNCODE E_FILE              = -202;
RETURNCODE E_FILEPOSITION      = -203;
RETURNCODE E_FILESIZE          = -204;
RETURNCODE E_READFILE          = -205;
RETURNCODE E_WRITEFILE         = -206;
RETURNCODE E_CLOSEFILE         = -208;
RETURNCODE E_FLUSHFILE         = -209;

class FileStream :
	public StreamConvert< FileStream >
{
	HANDLE m_file;

protected:
	uint32 SeekFile(uint64 filePos , uint64& newPos , SEEK_POSITION seekPos );
	int32 CheckFileInvalid();

public:

	FileStream();

	enum OPEN_MODE
	{
		CREATE = 1,
		READ   = 1<<8,
		WRITE  = 2<<8,
		ALL    = 3<<8,
		SHARE_READ   =1<<16,
		SHARE_WRITE  =2<<16
	};

	int32 Open( ctchar* fileName , uint32 mode = READ | SHARE_READ );
	virtual int32 CanRead();
	virtual int32 CanSeek();
	virtual int32 HaveEOS();
	virtual int32 Seek( uint64 position , SEEK_POSITION flag = CURRENT );
	virtual int32 GetPosition( uint64& position );
	virtual int32 CanWrite();
	virtual int32 GetSize( uint64& size );
	virtual int32 Read(  byte* block , uint32 blockSize , uint32& fileRead );
	virtual int32 Write( byte* block , uint32 blockSize , uint32& fileRead );
	virtual int32 EndOfStream();
	virtual int32 Close();
	virtual int32 Flush();
	~FileStream();

};

#endif